package com.example.yixueban.controller;

//import com.example.yixueban.domain.Admin;
import com.example.yixueban.req.main.Login_Req;
import com.example.yixueban.req.main.Register_Req;
import com.example.yixueban.req.main.TeacherList_Req;
import com.example.yixueban.resp.CommonResp;
import com.example.yixueban.resp.login.AccountInfo_resp;
import com.example.yixueban.service.AdminServiceImpl;
import com.example.yixueban.service.CheckErrorImpl;
import com.example.yixueban.service.MainServiceImpl;
import com.example.yixueban.service.UserServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/main")
public class MainController {
    @Resource
    private MainServiceImpl mainService;
    @Resource
    private UserServiceImpl userService;
    @Resource
    private AdminServiceImpl adminService;
    @Resource
    private CheckErrorImpl checkErrorService;

    @PostMapping("/login")
    public CommonResp login(@RequestBody Login_Req loginReq){
        System.out.println("main/login");
        CommonResp<AccountInfo_resp> resp = new CommonResp<>();
  /*      System.out.println("user_number:" + loginReq.getUser_number());
        System.out.println("password:" + loginReq.getPassword());
        System.out.println("telephone:" + loginReq.getTelephone());
        System.out.println("code:" + loginReq.getCode());
        System.out.println("identity:" + loginReq.getIdentity());*/
        if (loginReq.getPassword().equals("")&&loginReq.getTelephone().equals("")){
            //输入了账号但是没写密码
           // System.out.println("请输入密码登录");
            resp.setSuccess(false);
            resp.setMessage("请输入密码登录");
            return resp;
        }
        AccountInfo_resp accountInfo_resp = mainService.login(loginReq);
        if (accountInfo_resp.getTemp() == 0) {
            resp.setContent(accountInfo_resp);
        } else {
            resp.setSuccess(false);
            if (accountInfo_resp.getTemp() == 1)
                resp.setMessage("登录失败，账号密码不匹配");
            else
                resp.setMessage("验证码错误");

        }
        return resp;

    }

    @GetMapping(value = "/logout/{user_id}")
    public CommonResp logout(@PathVariable("user_id") String user_id){
        System.out.println("enter logout");
        CommonResp<AccountInfo_resp> resp = new CommonResp<>();
        resp.setMessage("注销成功");
        return resp;
    }






    @PostMapping("/register")
    public CommonResp register(@RequestBody Register_Req register_req){
        CommonResp<List<AccountInfo_resp>> resp = new CommonResp<>();
        /*注册考虑到 注册用户信息 创建新的钱包 设置年级*/
        AccountInfo_resp registerResult = mainService.register(register_req);
        System.out.println("registerResult.getTemp(): "+registerResult.getTemp());
        if (registerResult.getTemp()==1){
            resp.setSuccess(false);
            resp.setMessage("已经有同名的账号，建议改个账号试试");
        }else if (registerResult.getTemp()==2){
            resp.setSuccess(false);
            resp.setMessage("创建账号失败，请重试一下");
        }else if(registerResult.getTemp()==0)
            resp.setMessage("创建成功");
//        resp.setContent(list);
        return resp;
    }


//    @GetMapping("/adminRegister")
//    public Admin adminRegister(){
//        Admin admin = new Admin();
//        return admin;
//    }


    @GetMapping("/teacherList")
    public CommonResp getTeacherList(){
        CommonResp<List<TeacherList_Req>> resp = new CommonResp<>();
        List<TeacherList_Req> teacherList_reqList=mainService.getTeacherReqList();
        resp.setContent(teacherList_reqList);
        return resp;
    }


}
